package com.codegeek;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * 启动程序
 *
 * @author codegeek
 */
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@EnableScheduling
@ServletComponentScan
public class RuoYiApplication
{
    /**
     * @return
     * 注入tomcat 传递参数匹配正则允许<>[\]^`{|}./$@ 符号 为嵌入式Tomcat设置'relaxedQueryChars'
     */
//    @Bean
//    public WebServerFactoryCustomizer<TomcatServletWebServerFactory>
//    containerCustomizer(){
//        return new EmbeddedTomcatCustomizer();
//    }
//
//    private static class EmbeddedTomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
//
//        @Override
//        public void customize(TomcatServletWebServerFactory factory) {
//            factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
//                connector.setAttribute("relaxedPathChars", "<>[\\]^`{|}./$@");
//                connector.setAttribute("relaxedQueryChars", "<>[\\]^`{|}./$@");
//            });
//        }
//    }
    public static void main(String[] args)
    {
//        System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
//        System.setProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow", "|{}");

        // System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(RuoYiApplication.class, args);
        System.out.println("(♥◠‿◠)ﾉﾞ  边坡监测启动成功   ლ(´ڡ`ლ)ﾞ  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
    }

    @Bean
    public NamedParameterJdbcTemplate namedParameterJdbcTemplate (JdbcTemplate jdbcTemplate){
       return new NamedParameterJdbcTemplate(jdbcTemplate);
    }


    @Bean
    public ServletRegistrationBean<StatViewServlet> druidStatViewServlet() {
        ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>(new StatViewServlet(),  "/druid/*");
        // IP白名单 (没有配置或者为空，则允许所有访问)
        registrationBean.addInitParameter("allow", "127.0.0.1");
        // IP黑名单 (存在共同时，deny优先于allow)
        registrationBean.addInitParameter("deny", "");
        registrationBean.addInitParameter("loginUsername", "no access.to。");
        registrationBean.addInitParameter("loginPassword", "-_!@%&&^&!*@)!*#!*@(");
        registrationBean.addInitParameter("resetEnable", "false");
        return registrationBean;
    }
}
